<?php
/**
 * 签到设置
 */

namespace app\api\model;
use think\Model;

class SignSet extends Model
{
    /**
    * 获取签到设置
    * @param mid int 会员id
    */
    public function _list($mid){
        $model = new Member;
        $member = $model->_getInfoById($mid);
        $num = $member['sign_continuity_seven_num'];//七天连续签到次数
        $list = $this->field('title, sign_key, gold')->select()->toArray();
        if($num == 0){
            foreach($list as $k=>$v){
                $list[$k]['is_sign'] = -1;
            }
            
        }else{
            foreach($list as $k=>$v){
                if($v['sign_key'] <= $num){
                    $list[$k]['is_sign'] = 1;
                }else{
                    $list[$k]['is_sign'] = -1;
                }
                
            }
        }
        
        return $list;
    }
    
    /**
    * 通过连续签到天数获取信息
    */
    public function _getInfoByKey($key){
        return $this->where([['sign_key', '=', $key]])->find();
    }
}